package seg2500.messagerie.texte;

import java.awt.*;
import java.awt.event.*;
import java.io.IOException;
import com.lloseng.ocsf.client.*;
import java.util.*;
import seg2500.messagerie.Session;

public class TexteFrame extends Frame
{
  private Button closeB =     new Button("Close");
  private Button sendB =      new Button("Send");
  private TextField message = new TextField();
  private Label messageLB =   new Label("Message: ", Label.RIGHT);
  private java.awt.List liste =        new java.awt.List();
  private TexteClient controller;

  public TexteFrame()
  {
    super("Messagerie Textuelle");


    addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent e)
      {
        close();
      }
    });


    closeB.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e)
      {
        close();
      }
    });


    sendB.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e)
      {
        controller.send(message.getText());
      }
    });

    Panel bottom = new Panel();
    bottom.setLayout(new GridLayout(2,2,5,5));

    bottom.add(messageLB);
    bottom.add(message);
    bottom.add(sendB);
    bottom.add(closeB);

    setLayout(new BorderLayout(5,5));
    add("Center", liste);
    add("South", bottom);
    setSize(300,400);
    setVisible(true);
  }

	public void setController(TexteClient c) 
	{
       controller= c;
	}

	public void display(String texte) 
	{
		liste.add(texte);
		liste.makeVisible(liste.getItemCount()-1);
		liste.setBackground(Color.yellow);
	}


  public void close()
  {
    setVisible(false);
  }
}
